package com.mapler.autoresponder.ui;

import com.mapler.ui.*;
import com.mapler.model.AdModel;
import com.mapler.model.SModel;
import com.mapler.model.UAModel;
import com.mapler.service.INotifier;
import com.mapler.utility.HttpHelper;
import com.mapler.utility.IConstant;
import java.awt.Color;
import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import javax.swing.JFileChooser;
import javax.swing.SwingUtilities;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Node;

/**
 *
 * @author mithun
 */
public class AutoResponderREmailUI extends javax.swing.JPanel implements INotifier {

    private static Logger log = Logger.getLogger(AccountsUI.class);
    private String username;
    private String password;
    private String country;
    private INotifier iNotifier;
    private SModel sModel;
    private ArrayList<UAModel> uaModels;
    private ArrayList<AdModel> addModels;
    private HashMap<String, UAModel> usHashMap;
    private HashMap<Integer, ArrayList<AdModel>> addMap = new HashMap();
    private int globalWhichSlot = 0;
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    /**
     * Creates new form AccountsUI
     */
    public AutoResponderREmailUI() {
        initComponents();
        initUI();
    }

    public AutoResponderREmailUI(String username, String password, String country) {
        this.username = username;
        this.password = password;
        this.country = country;
        initComponents();
        initUI();
    }

    public void initUI() {
        DefaultTableModel model = (DefaultTableModel) jTAccountsTbl.getModel();
        model.addTableModelListener(new TableModelListener() {
            @Override
            public void tableChanged(TableModelEvent e) {
                if (e.getType() == TableModelEvent.UPDATE) {
                    
                }
            }
        });
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        message = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTAccountsTbl = new javax.swing.JTable();
        jBRefresh = new javax.swing.JButton();
        jCBIsHeader = new javax.swing.JCheckBox();
        jTFile = new javax.swing.JTextField();
        jBFileSelector = new javax.swing.JButton();
        jBImport = new javax.swing.JButton();

        message.setText("Message");

        jButton1.setText("ReLoad");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTAccountsTbl.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Serial", "Email", "Password", "Protocal", "Server", "Port", "Status"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTAccountsTbl);

        jBRefresh.setText("Refresh");
        jBRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBRefreshActionPerformed(evt);
            }
        });

        jCBIsHeader.setText("Is Header");

        jBFileSelector.setText("Select file...");
        jBFileSelector.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBFileSelectorActionPerformed(evt);
            }
        });

        jBImport.setText("Import");
        jBImport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBImportActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 784, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jTFile, javax.swing.GroupLayout.PREFERRED_SIZE, 328, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBFileSelector)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jBImport))
                            .addComponent(jCBIsHeader))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton1)
                        .addGap(2, 2, 2)
                        .addComponent(jBRefresh))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(message, javax.swing.GroupLayout.PREFERRED_SIZE, 607, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(message, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jBRefresh)
                            .addComponent(jButton1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jCBIsHeader)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jBFileSelector)
                            .addComponent(jBImport))))
                .addContainerGap(49, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

   
    public void loadAccounts() {
        try {
            //JCheckBox checkBox = new javax.swing.JCheckBox();
            //jTAccountsTbl.getColumn("Action").setCellEditor(new DefaultCellEditor(checkBox));

            DefaultTableModel model = (DefaultTableModel) jTAccountsTbl.getModel();
            model.setRowCount(0);
            String uri = "http://" + IConstant.HOSTNAME + "/index.php?r=autoresponderRemail/getReaderEamil&username="
                    + this.username + "&password=" + this.password;
            String response = HttpHelper.post(new URL(uri), "");
            Document document = DocumentHelper.parseText(response);
            String errorCode = document.valueOf("Response/errorcode");
            if (!errorCode.equalsIgnoreCase("000")) {
                List<Node> list = document.selectNodes("/Response/accounts/account");
                for (Node node : list) {
                    String statusText = "";
                   
                    model.addRow(new Object[]{node.valueOf("id"),
                                node.valueOf("email"),
                                node.valueOf("password"),
                                node.valueOf("protocal"),
                                node.valueOf("server"),
                                node.valueOf("port"),
                                statusText});
                }
            }
        } catch (Throwable ex) {
            log.debug("Error " + ex);
            ex.printStackTrace();
        }
    }
    
    private void jBRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBRefreshActionPerformed
        this.globalWhichSlot = 0;
    }//GEN-LAST:event_jBRefreshActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            initSettings();
        } catch (Throwable ex) {
            log.debug("Error " + ex);
            ex.printStackTrace();
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jBImportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBImportActionPerformed
        try {
            if (jTFile.getText().isEmpty()) {
                return;
            }
            FileInputStream file = new FileInputStream(jTFile.getText());
            HSSFWorkbook workbook = new HSSFWorkbook(file);
            HSSFSheet sheet = workbook.getSheetAt(0);
            Iterator<Row> rowIterator = sheet.iterator();
            boolean isHeader = jCBIsHeader.isSelected();
            int successc = 0;
            int failc = 0;
            while (rowIterator.hasNext()) {
                Row row = rowIterator.next();
                if (isHeader) {
                    isHeader = false;
                    continue;
                }

                StringBuilder request = new StringBuilder();
                request.append("<Request>");
                request.append("<username>").append(this.username).append("</username>");
                request.append("<password>").append(this.password).append("</password>");

                if (row.getCell(0) != null) {
                    request.append("<email>").append(row.getCell(0)).append("</email>");
                } else {
                    request.append("<email>").append("").append("</email>");
                }

                if (row.getCell(1) != null) {
                    request.append("<password>").append(row.getCell(1)).append("</password>");
                } else {
                    request.append("<password>").append("").append("</password>");
                }

                if (row.getCell(2) != null) {
                    request.append("<server>").append(row.getCell(2)).append("</server>");
                } else {
                    request.append("<server>").append("").append("</server>");
                }
                
                if (row.getCell(3) != null) {
                    request.append("<protocal>").append(row.getCell(3)).append("</protocal>");
                } else {
                    request.append("<protocal>").append("").append("</protocal>");
                }
                
                if (row.getCell(4) != null) {
                    request.append("<port>").append(row.getCell(4)).append("</port>");
                } else {
                    request.append("<port>").append("").append("</port>");
                }

                request.append("</Request>");
                String req = URLEncoder.encode(request.toString(), "UTF-8");
                String uri = "http://" + IConstant.HOSTNAME + "/index.php?r=autoresponderRemail/addReaderEamil";
                String param = "request=" + req;
                String response = HttpHelper.post(new URL(uri), param);

                Document document = DocumentHelper.parseText(response);
                String errorCode = document.valueOf("Response/errorcode");
                String msg = document.valueOf("Response/message");
                if (errorCode.equalsIgnoreCase("000")) {
                    failc++;
                    this.message.setBackground(Color.red);
                } else {
                    successc++;
                    this.message.setBackground(Color.black);
                }
                this.message.setText(msg);
            }
            int tCount = successc + failc;
            String msg = "Total record:" + tCount + " successfully imported:" + successc + " failed:" + failc;
            this.message.setText(msg);
        } catch (Throwable ex) {
            message.setText("Error " + ex.getMessage());
            log.debug("Error " + ex);
        }
    }//GEN-LAST:event_jBImportActionPerformed

    private void jBFileSelectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBFileSelectorActionPerformed
        try {
            JFileChooser fc = new JFileChooser();
            fc.addChoosableFileFilter(new OnlyExt());

            int returnval = fc.showOpenDialog(null);
            if (returnval == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                jTFile.setText(file.getPath());
            }
        } catch (Throwable ex) {
            message.setText("Error " + ex.getMessage());
            log.debug("Error " + ex);
        }
    }//GEN-LAST:event_jBFileSelectorActionPerformed
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBFileSelector;
    private javax.swing.JButton jBImport;
    private javax.swing.JButton jBRefresh;
    private javax.swing.JButton jButton1;
    private javax.swing.JCheckBox jCBIsHeader;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTAccountsTbl;
    private javax.swing.JTextField jTFile;
    private javax.swing.JLabel message;
    // End of variables declaration//GEN-END:variables

    public void initSettings() {
        this.setsModel(null);
        //this.setUaModels(null);
        this.setAddModels(null);
        this.setUsHashMap(null);
        this.fillSetting(this.getsModel());
        //this.fillUserAccount(this.getUaModels());
        this.fillAdd(this.getAddModels());
    }

    private void fillAdd(ArrayList<AdModel> addModels) {
        try {
            String uri = "http://" + IConstant.HOSTNAME + "/index.php?r=advertisement/getAdvertisement&username="
                    + this.username + "&password=" + this.password;
            String response = HttpHelper.post(new URL(uri), "");
            Document document = DocumentHelper.parseText(response);
            String errorCode = document.valueOf("Response/errorcode");
            if (!errorCode.equalsIgnoreCase("000")) {
                List<Node> list = document.selectNodes("/Response/accounts/account");
                for (Node node : list) {
                    AdModel model = new AdModel();
                    model.setId(node.valueOf("id"));
                    model.setDescription(node.valueOf("description"));
                    model.setTitle(node.valueOf("title"));
                    model.setRemarks(node.valueOf("remarks"));
                    model.setCompensation(node.valueOf("compensation"));
                    model.setAge(node.valueOf("age"));
                    model.setBody(node.valueOf("body"));
                    model.setHeight(node.valueOf("height"));
                    model.setStatus(node.valueOf("status"));
                    model.setLikes(node.valueOf("likes"));

                    if (node.valueOf("slot") != null && !this.getAddMap().containsKey(Integer.valueOf(node.valueOf("slot")))) {
                        this.getAddMap().put(Integer.valueOf(node.valueOf("slot")), new ArrayList<AdModel>());
                    }
                    this.getAddMap().get(Integer.valueOf(node.valueOf("slot"))).add(model);
                    addModels.add(model);
                }
            }
        } catch (Throwable ex) {
            ex.printStackTrace();
        }
    }

    private void fillUserAccount(ArrayList<UAModel> uaModels) {
        try {
            String uri = "http://" + IConstant.HOSTNAME + "/index.php?r=account/getAccounts&username="
                    + this.username + "&password=" + this.password + "&working=1";
            String response = HttpHelper.post(new URL(uri), "");
            Document document = DocumentHelper.parseText(response);
            String errorCode = document.valueOf("Response/errorcode");
            if (!errorCode.equalsIgnoreCase("000")) {
                List<Node> list = document.selectNodes("/Response/accounts/account");
                for (Node node : list) {
                    UAModel model = new UAModel();
                    model.setId(node.valueOf("id"));
                    model.setEmail(node.valueOf("email"));
                    model.setEmailPassword(node.valueOf("email_pass"));
                    model.setClientPassword(node.valueOf("cl_pass"));
                    model.setForwardEmail(node.valueOf("fw_email"));
                    model.setForwardEmailPass(node.valueOf("fw_email_pass"));
                    model.setPhone(node.valueOf("phone"));
                    model.setState(node.valueOf("state"));
                    model.setLink(node.valueOf("link"));
                    model.setProxy(node.valueOf("proxy"));
                    model.setRemarks(node.valueOf("remarks"));
                    model.setProxyIp(node.valueOf("proxy_ip"));
                    model.setProxyPort(Integer.parseInt(node.valueOf("proxy_port")));
                    model.setProxyUsername(node.valueOf("proxy_username"));
                    model.setProxyPassword(node.valueOf("proxy_password"));
                    uaModels.add(model);
                    this.getUsHashMap().put(node.valueOf("id"), model);
                }
            }
        } catch (Throwable ex) {
            ex.printStackTrace();
        }
    }

    private void fillSetting(SModel sModel) {
        try {
            String uri = "http://" + IConstant.HOSTNAME + "/index.php?r=setting/getSetting&username="
                    + this.username + "&password=" + this.password;
            String response = HttpHelper.post(new URL(uri), "");
            if (response.isEmpty()) {
                return;
            }
            Document document = DocumentHelper.parseText(response);
            String errorCode = document.valueOf("Response/errorcode");
            if (!errorCode.equalsIgnoreCase("000")) {
                sModel.setRecordId(document.valueOf("/Response/setting/id"));
                sModel.setPostPerIP(document.valueOf("/Response/setting/post_per_ip"));
                sModel.setPostInterval(document.valueOf("/Response/setting/post_interval"));
                sModel.setUpage(document.valueOf("/Response/setting/upper_age"));
                sModel.setLwage(document.valueOf("/Response/setting/lower_age"));
                sModel.setLogincl(document.valueOf("/Response/setting/login_cl"));
                sModel.setUseLocation(document.valueOf("/Response/setting/use_location"));
                sModel.setRandomSubarea(document.valueOf("/Response/setting/random_subarea"));
                sModel.setUseAge(document.valueOf("/Response/setting/use_age"));
                sModel.setMaxWaitTime(document.valueOf("/Response/setting/max_wait_time"));
                sModel.setUseFWlink(document.valueOf("/Response/setting/use_fw_email"));

                sModel.setLogAutoScroll(document.valueOf("/Response/setting/log_auto_scroll"));
                sModel.setAutoPost(document.valueOf("/Response/setting/auto_post"));
                sModel.setChangeIP(document.valueOf("/Response/setting/change_ip"));
                sModel.setName(document.valueOf("/Response/setting/user_name"));
                sModel.setPass(document.valueOf("/Response/setting/upass"));
                sModel.setUseProxy(document.valueOf("/Response/setting/use_proxy"));
                sModel.setMaxTry(document.valueOf("/Response/setting/max_try"));
                sModel.setVpnName(document.valueOf("/Response/setting/vpn_name"));
                //this.countryUI.setText(document.valueOf("/Response/setting/country_id"));

                sModel.setPostfix(document.valueOf("/Response/setting/postfix"));
                sModel.setPrefix(document.valueOf("/Response/setting/prefix"));
                sModel.setIePath(document.valueOf("/Response/setting/ie_path"));
                sModel.setFfPath(document.valueOf("/Response/setting/ff_path"));
                sModel.setGcPath(document.valueOf("/Response/setting/gc_path"));

                sModel.setJob(document.valueOf("/Response/setting/job"));
                sModel.setDriver(document.valueOf("/Response/setting/driver"));
                sModel.setAccountID(document.valueOf("/Response/setting/accountid"));
                sModel.setVpnName(document.valueOf("/Response/setting/vpn"));
                sModel.setWebMail(false);

                if (document.valueOf("/Response/setting/jCBWebEmail").equalsIgnoreCase("1")) {
                    sModel.setWebMail(true);
                }

                sModel.setCloseBrowser(false);
                if (document.valueOf("/Response/setting/close_browser").equalsIgnoreCase("1")) {
                    sModel.setCloseBrowser(true);
                }

                sModel.setRandom(false);
                if (document.valueOf("/Response/setting/random").equalsIgnoreCase("1")) {
                    sModel.setRandom(true);
                }

                sModel.setDeletePost(false);
                if (document.valueOf("/Response/setting/delete_post").equalsIgnoreCase("1")) {
                    sModel.setDeletePost(true);
                }

                sModel.setUpdateAccount(false);
                if (document.valueOf("/Response/setting/update_account").equalsIgnoreCase("1")) {
                    sModel.setUpdateAccount(true);
                }

                sModel.setProxyType(false);
                if (document.valueOf("/Response/setting/proxy_type").equalsIgnoreCase("1")) {
                    sModel.setProxyType(true);
                }

                sModel.setUseProxy("0");
                if (document.valueOf("/Response/setting/use_proxy").equalsIgnoreCase("1")) {
                    sModel.setUseProxy("1");
                }

                sModel.setUseSlot(false);
                if (document.valueOf("/Response/setting/use_slot").equalsIgnoreCase("1")) {
                    sModel.setUseSlot(true);
                }

                sModel.setPostInSession(false);
                if (document.valueOf("/Response/setting/post_insame_session").equalsIgnoreCase("1")) {
                    sModel.setPostInSession(true);
                }

                sModel.setRenewItems(document.valueOf("/Response/setting/renew"));

                sModel.setResourcesHide(false);
                if (document.valueOf("/Response/setting/hide_resources").equalsIgnoreCase("1")) {
                    sModel.setResourcesHide(true);
                }

                sModel.setResourcesHide(false);
                if (document.valueOf("/Response/setting/hide_resources").equalsIgnoreCase("1")) {
                    sModel.setResourcesHide(true);
                }

                if (StringUtils.isNotBlank(document.valueOf("/Response/setting/slot_no"))) {
                    int slot = Integer.parseInt(document.valueOf("/Response/setting/slot_no"));
                    sModel.setSlotNo(slot);
                }
                
                sModel.setRunIndividually(false);
                if (document.valueOf("/Response/setting/run_individual").equalsIgnoreCase("1")) {
                    sModel.setRunIndividually(true);
                }
                sModel.setDomainInfo(document.valueOf("/Response/setting/domain_info"));
                
                if (StringUtils.isNotBlank(document.valueOf("/Response/setting/email_read_try"))) {
                    int emailReadTry = Integer.parseInt(document.valueOf("/Response/setting/email_read_try"));
                    sModel.setEmailReadTry(emailReadTry);
                }
            }
        } catch (Throwable ex) {
            ex.printStackTrace();
        }
    }

    public SModel getsModel() {
        if (sModel == null) {
            sModel = new SModel();
        }
        return sModel;
    }

    public void setsModel(SModel sModel) {
        this.sModel = sModel;
    }

    public ArrayList<UAModel> getUaModels() {
        if (uaModels == null) {
            uaModels = new ArrayList<UAModel>();
        }
        return uaModels;
    }

    public void setUaModels(ArrayList<UAModel> uaModels) {
        this.uaModels = uaModels;
    }

    public ArrayList<AdModel> getAddModels() {
        if (addModels == null) {
            addModels = new ArrayList<AdModel>();
        }
        return addModels;
    }

    public void setAddModels(ArrayList<AdModel> addModels) {
        this.addModels = addModels;
    }

    public HashMap<String, UAModel> getUsHashMap() {
        if (usHashMap == null) {
            usHashMap = new HashMap<String, UAModel>();
        }
        return usHashMap;
    }

    public void setUsHashMap(HashMap<String, UAModel> usHashMap) {
        this.usHashMap = usHashMap;
    }

    public HashMap<Integer, ArrayList<AdModel>> getAddMap() {
        return addMap;
    }

    public void setAddMap(HashMap<Integer, ArrayList<AdModel>> addMap) {
        this.addMap = addMap;
    }

    @Override
    public void notify(final String info) {
        try {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    message.setText(info);
                }
            });
        } catch (Throwable ex) {
            log.debug("notify:: Error causes " + ex.getMessage());
        }
    }

    public INotifier getiNotifier() {
        if (iNotifier == null) {
            iNotifier = this;
        }
        return iNotifier;
    }

    @Override
    public void write(String info) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}